﻿<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@page import="com.util.SuperPage"%>
<%@page import="com.util.SuperFile"%>
<%@page import="com.util.SuperString"%>
<%@page import="com.mtbu.comm.Util"%>
<%@page import="com.mtbu.bean.*"%>
<%@page import="com.mtbu.dao.*"%>
<%@page import="my.myorm.tool.jdbc.SQLExecutor"%>
<%@page import="my.myorm.tool.jdbc.SQLManager"%>
<%@page import="my.myorm.tool.jdbc.Pages"%>
<%@page import="my.myorm.tool.jdbc.ResultList"%>
<%@page import="my.tool.ConfigProp" %>

<%@include file="sys_commcheck.jsp"%>


<%!
    public String createStateWord(int state){

        if(1 == state) return "<font color=\"#0033FF\">正常</font>";
        if(2 == state) return "<font color=\"#ff3300\">异常</font>";
        return "<font color=\"#999999\">未知</font>";
    }

	public String createStepHref(HttpServletRequest request,boolean isBackStep,Project project,Channel channel) throws Exception {

		//Step step = isBackStep ? channel.getStep().getPreStep() : channel.getStep()
		//
		//=
		//

		Step step = channel.getStep();

		//System.out.println("isBackStep:" + isBackStep);
		//System.out.println("getType:" + step.getPreStep().getType());

		if ( isBackStep && step.getPreStep().getType() == 2 )
		{
			return "回退";
		}

		if ( !isBackStep && step.getNextStep() == null )
		{
			return "完成";
		}

		String curFile = SuperPage.getCurURLFile(request);
		String modFileDo = SuperFile.getFileName(curFile) + "moddo.jsp";


		return String.format(
			"<a href=\"%1$s?act=%2$s&ids=%3$s%4$s\">%5$s</a>" ,
			"channelflowmoddo.jsp",
			isBackStep ? "stepback" : "stepnext" ,
			channel.getId(),
			SuperPage.getQueryAnd(request,"act,ids"),
			isBackStep ? "回退" : step.getName()
		);
	}


	public String createStepDelChannelHref(HttpServletRequest request,boolean isAllowDel ,Channel channel){
		if ( isAllowDel == false )
		{
			return "删除";
		}
		else{
			return String.format(
				"<a href=\"%1$s?act=%2$s&ids=%3$s%4$s\">%5$s</a>" ,
				"channelflowmoddo.jsp",
				"del",
				channel.getId(),
				SuperPage.getQueryAnd(request,"act,ids"),
				"删除"
			);
		}
	}

%>

<%
    String curFile = SuperPage.getCurURLFile(request);

    //System.out.println("curFile:" + curFile);
    //System.out.println("request:" + request.getRequestURI());

    String modFile = SuperFile.getFileName(curFile) + "mod.jsp";
    String readFile = SuperFile.getFileName(curFile) + "read.jsp";
    String modFileDo = SuperFile.getFileName(curFile) + "moddo.jsp";
    String viewFile = SuperFile.getFileName(curFile) + "view.jsp";



    String s_id=SuperString.notNullTrim(request.getParameter("s_id"));

    String s_platform=SuperString.notNullTrim(request.getParameter("s_platform"));
    String s_hv=SuperString.notNullTrim(request.getParameter("s_hv"));
    String s_osv=SuperString.notNullTrim(request.getParameter("s_osv"));
    String s_sv=SuperString.notNullTrim(request.getParameter("s_sv"));

    int s_status=SuperString.getInt(request.getParameter("s_status"),-1);

    String s_playtype=SuperString.notNullTrim(request.getParameter("s_playtype"));
	String pid=SuperString.notNullTrim(request.getParameter("pid"));



	Project project = DAOManager.projectDao.findProject(pid);
	boolean isAllowDel = project.isAllowDelChannel(Constant_User);

	String curName = project.getName();

    int s_pagesize=SuperString.getInt(request.getParameter("s_pagesize"));

    String dropparam="s_playtype,s_id,s_platform,s_hv,s_osv,s_sv,s_status,s_pagesize,issearch";

//  String testStr = SuperPage.getQueryQ(request,dropparam);
//  System.out.println("testStr:" + testStr);

    if(request.getMethod().equalsIgnoreCase("post")){
        StringBuffer sbparam=new StringBuffer();
        sbparam.append("&issearch=1");
        if(s_pagesize>0) sbparam.append("&s_pagesize=").append(s_pagesize);

        if(s_status>-1) sbparam.append("&s_status=").append(s_status);
        if(!"".equals(s_id)) sbparam.append("&s_id=").append(Util.encodeUrl(s_id));
        if(!"".equals(s_platform)) sbparam.append("&s_platform=").append(Util.encodeUrl(s_platform));
        if(!"".equals(s_hv)) sbparam.append("&s_hv=").append(Util.encodeUrl(s_hv));
        if(!"".equals(s_osv)) sbparam.append("&s_osv=").append(Util.encodeUrl(s_osv));
        if(!"".equals(s_sv)) sbparam.append("&s_sv=").append(Util.encodeUrl(s_sv));
        if(!"".equals(s_playtype)) sbparam.append("&s_playtype=").append(Util.encodeUrl(s_playtype));

        String strparam=sbparam.toString();
        if(strparam.startsWith("&")) strparam="?"+strparam.substring(1);
        strparam+="".equals(strparam)? SuperPage.getQueryQ(request,dropparam): SuperPage.getQueryAnd(request,dropparam);

        System.out.println("search:" + curFile+strparam);

        response.sendRedirect(curFile+strparam);
        return;
    }


    //组合条件
    StringBuffer strw = new StringBuffer();

    if(!"".equals(s_id)) strw.append(" and id like '%").append(s_id).append("%' ");
    if(!"".equals(s_platform)) strw.append(" and platform like '%").append(s_platform).append("%' ");
    if(!"".equals(s_hv)) strw.append(" and hv like '%").append(s_hv).append("%' ");
    if(!"".equals(s_osv)) strw.append(" and osv like '%").append(s_osv).append("%' ");
    if(!"".equals(s_sv)) strw.append(" and sv like '%").append(s_sv).append("%' ");
    if(!"".equals(s_playtype)) strw.append(" and playtype like '%").append(s_playtype).append("%' ");
    if(s_status>-1) strw.append(" and status=").append(s_status);





    String strwhere = Util.getWhereSQL(strw);
    //System.out.println("sql:" + strwhere);

    String order = SuperString.notNullTrim(request.getParameter("order"));
    String orderby = order.length() == 0 ? " order by id desc" :
            " order by " + order;

    SQLExecutor dbconn = SQLManager.getSQLExecutor();
    String sql = "select * from Channel"+ project.getSplit() + strwhere + orderby;
    System.out.println("sql:" + sql);
    int pagesize=Util.getPageSizeOfCookie(request,response,s_pagesize);
    Pages pages = new Pages(pagesize, "id", request);
    ResultList rs =dbconn.query(sql,false,pages);

%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title><%=curName%></title>
<link href="css/common.css" rel="stylesheet" type="text/css">
<script language="javascript" src="js/comm.js"></script>
<script language="javascript" src="js/tablecell.js"></script>
<script type="text/javascript" src="js/jquery.js" language="javascript"></script>
<script type="text/javascript" src="js/comm_confirm.js" language="javascript"></script>
<script type="text/javascript" src="js/pbx_tips.js" language="javascript"></script>
<style type="text/css">
a{
    text-decoration:none;
    color:#f30;
}
img{border:none;}
</style>
<script type="text/javascript">
var selall=false;
function allselect(){
    selall=!selall;
    var checks=document.getElementsByName("check_id");
    if(checks==null||checks==undefined) return;
    for(var i=0;i<checks.length;i++){
        checks[i].checked=selall;
    }
}
function batchIn(){
    var ids="";
    var checks=document.getElementsByName("check_id");
    if(checks==null||checks==undefined) return;
    for(var i=0;i<checks.length;i++){
        if(checks[i].checked){
           ids+=","+checks[i].value;
        }
    }
    window.location.href="bpp_channel_in_batchmod.jsp?act=batchin&ids="+ids;
}



</script>
</head>

<body onload="move()" onmousemove="canMove()" >
<div class="title_text"><%=curName%></div>
<fieldset class="order_fieldset">
    <legend>输入查询条件</legend>
    <table width="100%"  border="0" cellspacing="1" cellpadding="2" style="margin:5px 0;">
      <form name="form_s" action="<%=curFile%><%=SuperPage.getQueryQ(request,dropparam)%>" method="post" class="formline">
        <tr>
          <td >
            ID
            <input name="s_id" type="text" id="s_id" title="ID" value="<%=s_id%>" maxlength="30">
            Platform
            <input name="s_platform" type="text" id="s_platform" title="platform" value="<%=s_platform%>" maxlength="30">
            HV
            <input name="s_hv" type="text" id="s_hv" title="硬件型号" value="<%=s_hv%>" maxlength="30">
            OSV
            <input name="s_osv" type="text" id="s_osv" title="操作系统型号" value="<%=s_osv%>" maxlength="30">
            SV
            <input name="s_sv" type="text" id="s_sv" title="软件型号" value="<%=s_sv%>" maxlength="30">
            </td>
          <td width="9%" align="right">&nbsp;</td>
        </tr>
        <tr>
            <td>
              PlayType
              <input name="s_playtype" type="text" id="s_sv" title="播放协议" value="<%=s_playtype%>" maxlength="30">
            </td>
            <td width="9%" align="right">&nbsp;</td>
        </tr>
        <tr>
          <td >
            每页显示
            <input name="s_pagesize" type="text" id="s_pagesize" title="每页显示" value="<%=s_pagesize>0?s_pagesize:""%>" size="2" maxlength="6">
            <input name="Submit2" type="submit" class="BUTTON3" value=" 搜索 ">
          </td>
          <td width="9%" align="right">&nbsp;</td>
        </tr>
      </form>
    </table>
</fieldset>
<div style="height:2px;"><span/></div>


<div class="page_nav00">
<span class="page_search">页内查找:<input type="text" id="filterPageIpt" onkeyup="filtePage()" class="modinput"></span>
<span><input type="button" onclick="location.href='<%=modFile%>'" value=" 增加" class="BUTTON3" name="Submit"></span>
</div>
<table id="table_data" width="100%" border="0" cellpadding="1" cellspacing="1" class="table_bord">
  <tr class="table_bord_ttl">
    <td onClick="title_click('<%=Util.getOrderUrl("id",order,request)%>')">ID<%=Util.getOrderByImgHTML("id",order)%></td>
    <td onClick="title_click('<%=Util.getOrderUrl("channelid",order,request)%>')">ChannelId <%=Util.getOrderByImgHTML("channelid",order)%></td>
    <td onClick="title_click('<%=Util.getOrderUrl("updatetime",order,request)%>')">更新时间<%=Util.getOrderByImgHTML("updatetime",order)%></td>

    <td >操作</td>
  </tr>
<%
    String[] _status = new String[]{"normal","locked"};
    String[] _type_status = new String[]{"默认","自有"};
    String[] _statuscolors = new String[]{"#0033FF","#999999"};
    for(int i = 0; i < rs.size(); i++) {
        Channel record= rs.get(i).get(Channel.class);
        String trclass = i % 2 == 0 ? "tr_class1" : "tr_class2";
%>
  <tr name="datatr" class="<%=trclass%>" onMouseMove="cell_over(this);" onMouseOut="cell_out(this)" onClick="cell_click(this);" height="20">
    <td><%=record.getId()%></td>
    <td><%=record.getChannelId()%></td>
    <td><%=record.getUpdateTime_ToDateTimeString()%></td>

    <td>
		<!-- 后退操作 -->
		<%= createStepHref(request,true,project,record)%>
		<!-- 当前step操作 -->
		<%= createStepHref(request,false,project,record) %>
		<!-- 特殊 type=2的那个step -->
		<%= createStepDelChannelHref(request,isAllowDel,record) %>

    </td>

  </tr>
<%
    }
    if(rs.size()==0){
%>
  <tr bgcolor="#FFFFFF">
    <td height="50" colspan="20" align="center">没有数据</td>
  </tr>
  <%
    }
%>
</table>
    <div class="page_nav00">
   </div>
  <div class="page_nav00"><%=SuperPage.generatePageNavSingle(rs.getAllCount(), request, null, pages.getPageSize(),"个")%></div>
<div style="height:30px;"></div>
<script type="text/javascript">
$("body").children().not($("#table_data")).click(function(){cancelAllChecked();});
filtePage();
</script>
<%@include file="sys_commfooter.jsp"%>

</body>
</html>